package com.igeek.addTwoNumbers;

/**
 * @Author: zhiyu
 * @Date:19:48
 * @DESC:
 */
public class Test2 {
    public static void main(String[] args) {
        ListNode l1 = new ListNode(9,new ListNode(9,new ListNode(9,new ListNode(9))));
        ListNode l2 = new ListNode(9,new ListNode(9));
        ListNode listNode = test(l1, l2);
//        System.out.println(listNode.val);
    }
    public static ListNode test(ListNode l1 ,ListNode l2){
        ListNode result = new ListNode(0);
        ListNode current = result;
        int carry = 0;
        while (l1!=null||l2!=null||carry!=0){
            int sum = carry;
            if (l1!=null){
                sum+=l1.val;
                l1=l1.next;
            }
            if (l2!=null){
                sum+=l2.val;
                l2=l2.next;
            }
            carry = sum/10;
            current.next = new ListNode(sum%10);
            current = current.next;
            System.out.println(current.val);
        }
        return result.next;
    }
}
